//
//  HomeOriginalView.swift
//  BQWB
//
//  Created by laibingqiang on 16/10/26.
//  Copyright © 2016年 laibingqiang. All rights reserved.
//

import UIKit

class HomeOriginalView: UIView {

    var pic_cons:Constraint?
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var model:HomeStatusViewModel?{
        
        didSet{
            //发布时间
            timeL.text = model?.public_time
            //来自哪里
            comeL.text = model?.come_where
            //头像
            iconImgV.bq_setImage(withURLString: model?.statusModel?.user?.profile_image_url, placeholderImage: "avatar_default")
            //用户名
            nameL.text = model?.statusModel?.user?.name
            //微博内容
            contentL.text = model?.statusModel?.text
            //微博等级
            
            levelImgV.image = model?.levelImg
            //认证
           earImgV.image = model?.verifiedImg
            
            self.pic_cons?.uninstall()
            //判断是否显示配图
            if (model?.statusModel?.pic_urls?.count)! > 0{
                
                self.snp_updateConstraints(closure: { (make) in
                    self.pic_cons = make.bottom.equalTo(picV).offset(10).constraint
                })
                
                picV.isHidden = false
                
                picV.url_pics = model?.statusModel?.pic_urls
                
            }
            else
            {
                self.snp_updateConstraints(closure: { (make) in
                    self.pic_cons = make.bottom.equalTo(contentL).offset(10).constraint
                })
                
                picV.isHidden = true
            }
        }
    }

    func setupUI(){
        
        self.backgroundColor = UIColor(white: 237/256, alpha: 1.0)
        //添加子控件
        addSubview(iconImgV)
        addSubview(nameL)
        addSubview(levelImgV)
        addSubview(earImgV)
        addSubview(timeL)
        addSubview(comeL)
        addSubview(contentL)
        addSubview(picV)
        //设置约束
        iconImgV.snp_makeConstraints { (make) in
            
            make.left.top.equalTo(self).offset(10)
            make.size.equalTo(CGSize(width: 50, height: 50))
        }
        nameL.snp_makeConstraints { (make) in
            
            make.left.equalTo(iconImgV.snp_right).offset(10)
            make.top.equalTo(iconImgV)
        }
        levelImgV.snp_makeConstraints { (make) in
            
            make.left.equalTo(nameL.snp_right).offset(10)
            make.centerY.equalTo(nameL)
        }
        earImgV.snp_makeConstraints { (make) in
            
            make.centerX.equalTo(iconImgV.snp_right)
            make.centerY.equalTo(iconImgV.snp_bottom)
        }
        timeL.snp_makeConstraints { (make) in
            
            make.left.equalTo(nameL)
            make.bottom.equalTo(iconImgV)
        }
        comeL.snp_makeConstraints { (make) in
            
            make.top.equalTo(timeL)
            make.left.equalTo(timeL.snp_right).offset(10)
        }
        contentL.snp_makeConstraints { (make) in
            
            make.left.equalTo(iconImgV)
            make.top.equalTo(iconImgV.snp_bottom).offset(10)
            make.right.equalTo(self).offset(-20)
            //make.bottom.equalTo(self).offset(-10)
            
            
        }
        
        picV.snp_makeConstraints { (make) in
            make.top.equalTo(contentL.snp_bottom).offset(10)
            
            make.left.equalTo(contentL)
            
            
        }
        
        self.snp_makeConstraints { (make) in
            self.pic_cons = make.bottom.equalTo(picV).offset(10).constraint
        }
        
    }
    
    //懒加载
    //头像
    private lazy var iconImgV:UIImageView = {
        
        let imgV = UIImageView(imgName: "avatar_default")
        
        return imgV
    }()
    //名字
    private lazy var nameL:UILabel = {
        let n = UILabel(text: "大傻", textColor: UIColor.black, fontSize: BQBigFontSize)
        
        return n
    }()
    //微博等级
    private lazy var levelImgV:UIImageView = UIImageView(imgName: "common_icon_membership_expired")
    //兔耳朵
    private lazy var earImgV:UIImageView = UIImageView(imgName: "avatar_vgirl")
    //发表时间
    private lazy var timeL:UILabel = UILabel(text: "时间", textColor: BQTHEMECOLOR, fontSize: BQSmallFontSize)
    //来自哪里
    private lazy var comeL:UILabel = UILabel(text: "来自神奇的地方", textColor: BQTHEMECOLOR, fontSize: BQSmallFontSize)
    //内容
    private lazy var contentL:UILabel = {
        
        let l = UILabel(text: "曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼曹衙内是傻逼", textColor: UIColor.black, fontSize: BQNormalFontSize)
        l.numberOfLines = 0
        return l
        
    }()
    //配图
    private lazy var picV:PicCollectionView = {
        
        let view = PicCollectionView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
}
